var IyData = {
    //首页
    getUserType: function (userID, c) {
        var url='/Cyberspace/sys/user/'+userID;
        var xhr = $.ajax({
            type: 'get',
            url: url,
            dataType: 'json',
            timeout: 20000,
            success: function (r) {
                if (r.code == 1) {
                    cyb.init.d.userInfo={createUserInfo:r.result};
                    var userType = '';
                    switch (r.result.role.roleRank) {
                        case '2'://'值班员':
                        case 2:
                            userType = 1;
                            break;
                        case '1'://'领导':
                        case 1:
                            userType = 2;
                            break;
                        case '3'://'地方网信办':
                        case 3:
                            userType = 6;
                            break;
                        case '4'://设施运营单位
                        case 4:
                            userType = 8;
                            break;
                        case '5'://安全厂商
                        case 5:
                            userType = 7;
                            break;
                        case '6'://专家
                        case 6:
                            userType = 5;
                            break;
                    }
                    c(userType);
                } else {
                    comNotice.init(r.msg + '(Er001)' || 'Error');
                    //------IyData.reOAuth(r.code);
                }
            },
            complete: function (xml, s) {
                if (s == 'timeout') {
                    xhr.abort();
                    $('.iy-home').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getWarnNum: function (c) {
        var xhr = $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/baseTable/dataCount',
            dataType: 'json',
            timeout: 10000,
            success: function (r) {
                if (r.code == 1) {
                    c(r.result['warningCount']);
                } else {
                    comNotice.init(r.msg + '(Er002)' || 'Error');
                    //-----IyData.reOAuth(r.code);
                }
            },
            complete: function (xml, s) {
                if (s == 'timeout') {
                    xhr.abort();
                    $('.iy-scroll').remove();
                    IyBaseFun.e.$Body.append($('#timeOut').html());
                }
            }
        });
    },
    getShowCount: function (c) {
        var xhr = $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/baseTable/dataCount',
            dataType: 'json',
            timeout: 10000,
            success: function (r) {
                if(r.code==1){
                    c(r.result.taskCount)
                }else{
                    comNotice.init(r.msg)
                }
               // IyData.reOAuth(r.code);
            },
            complete: function (xml, s) {
                if (s == 'timeout') {
                    xhr.abort();
                    $('.iy-scroll').remove();
                    IyBaseFun.e.$Body.append($('#timeOut').html());
                }
            }
        });
    },
    homeList: function (c, pageNum, me) {
        $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/baseTable/getDynamicInformationList',
            data: {
                page: pageNum,
                size: cyb.init.d.pageSize
            },
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < cyb.init.d.pageSize) {
                        me.lock('down');
                        me.noData();
                        cyb.init.d.loadTab0End = true;
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.init.d.page_0++;
                    }
                    c(r.result);
                } else {
                    cyb.init.d.loadHomeError = true;//防死循环
                    comNotice.init(r.msg + '(Er004)' || "Error");
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function (xhr, type) {
                cyb.init.d.loadHomeError = true;
                me ? me.resetload() : "";
            }
        });
    },
    getWarnList: function (c, pageNum, me) {
        $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/riskManage',
            data: {
                userID: cyb.init.d.userID,
                page: pageNum,
                status:1,
                size: cyb.init.d.pageSize
            },
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    c(r.result);
                    if (r.result['records'].length < cyb.init.d.pageSize) {
                        me.lock('down');
                        me.noData();
                        cyb.init.d.loadTab1End = true;
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.init.d.page_1++;
                    }
                } else {
                    cyb.init.d.loadWarnError = true;
                    comNotice.init(r.msg + '(Er005)' || "Error");
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function (xhr, type) {
                me ? me.resetload() : "";
                cyb.init.d.loadWarnError = true;
            }
        });
    },
    getPush: function (id, c) {//---------------暂无推送,关闭此接口
        $.ajax({
            type: 'post',
            url: '/Cyberspace/main/isInfoPush.do',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (r) {
                c(r.code);
                //IyData.reOAuth(r.code);
            }
        });
    },
    //获取详情
    getDesc: function (id, c) {
        var url='/Cyberspace/sys/baseTable/'+id;
        var xhr = $.ajax({
            type: 'get',
            timeout: 10000,
            url: url,
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.iy-desc'));
            },
            success: function (r) {
                $('.iy-desc').find('.loadDiv').remove();
                if (r.code == 1) {
                    // var nr = r.result;
                    // if ('adviceMapList' in nr) {
                    //     nr.hasAdvice = nr['adviceMapList'].length > 0 ? true : false;
                    // } else {
                    //     nr['adviceMapList'] = []
                    // }
                    // if (nr.infoType == 2) {
                    //     nr['gradeLevel'] = cyb.desc.d.grade1[nr['grade']];
                    // }
                    // if (nr.infoType == 3) {
                    //     nr['gradeLevel'] = cyb.desc.d.grade2[nr['grade']];
                    // }
                    c(r.result);
                } else {
                    comNotice.init(r.msg);
                    //IyData.reOAuth(r.code);
                }
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.desc-bd').empty().append($('#timeOut').html());
                }
            }
        });
    },
    //工作情况
    getList: function (opts, c, me) {
        var dt = {//默认
            size: 20,
            //type: 1,
            page:1
        };
        var nd = $.extend(true, {}, dt, opts);
        if (nd['title'] != '') {
            nd['title'] = nd['title'];
        }else{
            delete nd['title']
        }
        var xhr = $.ajax({
            type: 'get',
            timeout: 10000,
            url: '/Cyberspace/sys/baseTable',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.toList.d['loadListEnd'] = true;
                        me.lock('down');
                        me.noData();
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.toList.d['page']++;
                    }
                    c ? c(r.result) : "";
                    me.resetload();
                } else {
                    cyb.toList.d['loadError'] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }

            },
            error: function () {
                cyb.toList.d['loadError'] = true;
                me ? me.resetload() : "";
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.list-scroll-box').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getAllEventList: function (opts, c, me) {
        var dt = {//默认
            size: 20,
            //type: 3,
            page:1
        };
        var nd = $.extend(true, {}, dt, opts);
        if (nd['title'] != '') {
            nd['title'] = nd['title'];
        }else{
            delete nd['title']
        }
        var xhr = $.ajax({
            type: 'get',
            timeout: 10000,
            url: '/Cyberspace/sys/eventManage',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.toList.d['loadListEnd'] = true;
                        me.lock('down');
                        me.noData();
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.toList.d['page']++;
                    }
                    c ? c(r.result) : "";
                } else {
                    cyb.toList.d['loadError'] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.toList.d['loadError'] = true;
                me ? me.resetload() : "";
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.list-scroll-box').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getAllRiskList: function (opts, c, me) {
        var dt = {//默认
            size: 20,
            type: 2,
            page:1
        };
        var nd = $.extend(true, {}, dt, opts);
        if (nd['title'] != '') {
            nd['title'] = nd['title'];
        }else{
            delete nd['title']
        }
        var xhr = $.ajax({
            type: 'get',
            timeout: 10000,
            url: '/Cyberspace/sys/riskManage',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.toList.d['loadListEnd'] = true;
                        me.lock('down');
                        me.noData();
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.toList.d['page']++;
                    }
                    c ? c(r.result) : "";
                } else {
                    cyb.toList.d['loadError'] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.toList.d['loadError'] = true;
                me ? me.resetload() : "";
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.list-scroll-box').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getAllReport: function (opts, c, me) {
        var dt = {
            linkdoodID: cyb.init.d.userID,
            size: 20,
            page: 1
        };
        var nd = $.extend(true, {}, dt, opts);
        var xhr = $.ajax({
            type: 'post',
            timeout: 10000,
            url: '/Cyberspace/sys/dailyReport/list',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.toList.d['loadListEnd'] = true;
                        me.lock('down');
                        me.noData();
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.toList.d['pageNum']++;
                    }
                    c ? c(r.result) : "";
                } else {
                    cyb.toList.d['loadError'] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.toList.d['loadError'] = true;
                me ? me.resetload() : "";
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.list-scroll-box').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getReportDesc2: function (opts, c, me) {
        var dt = {
            size: 20,
            page: 1
        };
        var nd = $.extend(true, {}, dt, opts);
        $.ajax({
            type: 'post',
            url: '/Cyberspace/sys/feedbackTable/summary',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.sum.d['loadListEnd'] = true;
                        me.lock('down');
                        me.noData();
                    } else {
                        me.unlock();
                        me.noData(false);
                        cyb.sum.d.pageNum++;
                    }
                    c ? c(r.result) : "";
                } else {
                    cyb.sum.d['loadError'] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.sum.d['loadError'] = true;
                me ? me.resetload() : "";
            }
        });
    },
    getReportDesc3: function (id,c) {
        var nd = {
            id: id
        };
        $.ajax({
            type: 'post',
            url: '/Cyberspace/sys/dailyReport/detail',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if(r.code==1){
                    c(r.result);
                }else{
                    comNotice.init(r.msg);
                }
                //IyData.reOAuth(r.code);
            }
        });
    },
    //我的上报
    getList2: function (type, c, me) {
        var nd = {
            userID:cyb.init.d.userID,
            page:cyb.addHome.d['page_' + type],//分页
            size:20
        };
        var xhr = $.ajax({
            type: 'get',
            timeout: 10000,
            url: '/Cyberspace/sys/baseTable',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.addHome.d['loadList' + type] = true;
                        if (type == cyb.addHome.d.isTab) {//当前正在此页时
                            me.lock('down');
                            me.noData();
                        }
                    } else {
                        if (type == cyb.addHome.d.isTab) {
                            me.unlock();
                            me.noData(false);
                        }
                        cyb.addHome.d['page_' + type]++;
                    }
                    c ? c(r.result) : "";
                } else {
                    cyb.addHome.d['loadError' + type] = true;
                    comNotice.init(r.msg || 'Error From Server');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.addHome.d['loadError' + type] = true;
                me ? me.resetload() : "";
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.aList-scroll').empty().append($('#timeOut').html());
                }
            }
        });
    },
    getDesc2: function (id, c) {
        var xhr = $.ajax({
            type: 'post',
            timeout: 10000,
            url: '/Cyberspace/main/getInfoDetail.do',
            data: {
                id: id
            },
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.mod-create'));
            },
            success: function (r) {
                $('.mod-create').find('.loadDiv').remove();
                if (r.code == 1) {
                    var nd = r.result, od = {};
                    if ('type' in nd) {
                        od['type'] = nd['type'].split(',');
                    }
                    if (nd['infoType'] != 1) {
                        var tad = cyb.add.d.scopeJson;
                        tad['eDesc'] = nd['effect_desc'];
                        tad['ip'] = nd['effectIp'].split(',');
                        tad['ym'] = nd['effectDomainname'].split(',');
                        tad['url'] = nd['effect_url'].split(',');
                        tad['ipList'] = [];
                        tad['ymList'] = [];
                        tad['urlList'] = [];
                        if (tad['ip'][0] != '') {
                            $.each(tad['ip'], function (i, v) {
                                tad['ipList'].push({ip: v});
                            });
                        }
                        if (tad['ym'][0] != '') {
                            $.each(tad['ym'], function (i, v) {
                                tad['ymList'].push({ym: v});
                            });
                        }
                        if (tad['url'][0] != '') {
                            $.each(tad['url'], function (i, v) {
                                tad['urlList'].push({url: v});
                            });
                        }
                        cyb.add.d['hasAreaCk'] = [];
                        cyb.add.d['hasIndustryCk'] = [];
                        var area = nd['regionids'].split(',');
                        var indus = nd['industryids'].split(',');
                        if (area[0] != '') {
                            cyb.add.d['hasAreaCk'] = area;
                        }
                        if (indus[0] != '') {
                            cyb.add.d['hasIndustryCk'] = indus;
                        }
                    }
                    c(nd, od);
                } else {
                    comNotice.init(r.msg);
                    //IyData.reOAuth(r.code);
                }
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                    $('.desc-bd').empty().append($('#timeOut').html());
                }
            }
        });
    },
    delInfo: function (id) {
        var xhr = $.ajax({
            type: 'post',
            timeout: 10000,
            url: '/Cyberspace/main/deleteInfo.do',
            data: {
                ids: id
            },
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.mod-create'));
            },
            success: function (r) {
                $('.mod-create').find('.loadDiv').remove();
                if (r.code == 1) {
                    comNotice.init('删除成功');
                    setTimeout(function () {
                        cyb.add.d.isPull = true;
                        $('.mh-left a').click();
                    }, 500);
                } else {
                    comNotice.init(r.msg);
                    //IyData.reOAuth(r.code);
                }
            },
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    xhr.abort();
                }
            }
        });
    },
    //情况报告---地方
    gerReport: function (type, c, me, pageNum) {
        var nd = {
            linkdoodID: cyb.init.d.userID,
            size: 20,
            page: pageNum,
            flag: type
        };
        $.ajax({
            type: 'post',
            url: '/Cyberspace/sys/dailyReport/list',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    if (r.result['records'].length < 20) {
                        cyb.report.d['loadList' + type] = true;
                        if (type == cyb.report.d.isTab) {//当前正在此页时
                            me.lock('down');
                            me.noData();
                        }
                    } else {
                        if (type == cyb.report.d.isTab) {
                            me.unlock();
                            me.noData(false);
                        }
                        cyb.report.d['page_' + type]++;
                    }
                    c(r.result);
                } else {
                    cyb.report.d['loadError' + type] = true;
                    comNotice.init(r.msg || '出错啦!');
                    //IyData.reOAuth(r.code);
                }
                me.resetload();
            },
            error: function () {
                cyb.toList.d['loadError' + type] = true;
                me ? me.resetload() : "";
            }
        });
    },
    getReportDesc: function (fid, c) {
        var nd = {
            fId: fid
        };
        $.ajax({
            type: 'post',
            url: '/Cyberspace/sys/dailyReport/detailSub',
            data: nd,
            dataType: 'json',
            success: function (r) {
                if (r.code == 1) {
                    c(r.result)
                } else {
                    comNotice.init(r.msg || "Error");
                }
            }
        });
    },
    // getDept: function (phone, c) {
    //     $.ajax({
    //         type: 'post',
    //         url: '/Cyberspace/main/getDeptByPhone.do',
    //         dataType: 'json',
    //         data: {
    //             phone: phone
    //         },
    //         success: function (r) {
    //             if (r.code == 1) {
    //                 c(r['result']);
    //             } else {
    //                 comNotice.init('获取单位失败');
    //                 IyData.reOAuth(r.code);
    //             }
    //         }
    //     });
    // },
    postReport: function (nd, c) {
        $.ajax({
            type: 'post',
            url: '/Cyberspace/sys/feedbackTable/update',
            data: nd,
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.reportForm'));
            },
            success: function (r) {
                $('.reportForm').find('.loadDiv').remove();
                if (r.code == 1) {
                    comNotice.init('反馈成功');
                    c();
                }
            }
        });
    },
    //类型
    getType: function (infoType) {
        var _t = this;
        var url;
        switch (infoType){
            case 2:
            case '2':
                url='/Cyberspace/sys/riskType';
                break;
            case 3:
            case "3":
                url='/Cyberspace/sys/eventType?parentID=0';
                break;
        }
        $.ajax({
            type: 'get',
            url: url,
            dataType: 'json',
            success: function (r) {
                if(r.code==1){
                    var s = cyb.add.d.selectList;
                    $.each(r.result, function (i, v) {
                        s['list'].push(v['name']);
                        s['code'].push(v['id']);
                        if (infoType == 3) {//如果是事件新增的话，请求子事件
                            _t.getSubType(v['id']);
                        }
                    });
                }else{
                    comNotice.init(r.msg)
                }
            }
        });
    },
    getSubType: function (code) {
        cyb.add.d.selectList['sub'][code] = {
            list: [],
            code: []
        };
        var url='/Cyberspace/sys/eventType?parentID='+code
        $.ajax({
            type: 'get',
            url: url,
            dataType: 'json',
            success: function (r) {
                if(r.code==1){
                    $.each(r.result, function (i, v) {
                        cyb.add.d.selectList['sub'][code]['list'].push(v['name']);
                        cyb.add.d.selectList['sub'][code]['code'].push(v['id'])
                    });
                }else{
                    comNotice.init(r.msg)
                }
            }
        });
    },
    addInfo: function (type,nd) {
        var url='';
        switch (type){
            case 1:
            case '1':
                url='/Cyberspace/sys/information';
                break;
            case 2:
            case '2':
                url='/Cyberspace/sys/risk';
                break;
            case 3:
            case '3':
                url='/Cyberspace/sys/event';
                break;
            default:
                break;
        }
        $.ajax({
            type: 'post',
            url: url,
            data: nd,
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.mod-create'));
                cyb.add.d.isReady = false;
                cyb.add.btn.closeTips();
            },
            success: function (r) {
                cyb.add.d.isReady = true;
                $('.loadDiv').remove();
                if (r.code == 1) {
                    comNotice.init('处理成功!');
                    setTimeout(function () {
                        cyb.add.d.isPull = true;
                        history.back();
                    }, 500);
                } else {
                    comNotice.init(r.result || r.msg);
                    //IyData.reOAuth(r.code);
                }
            },
            error: function () {
                cyb.add.d.isReady = true;
            }
        })
    },
    updateInfo: function (nd) {
        $.ajax({
            type: 'post',
            url: '/Cyberspace/main/update.do',
            data: nd,
            dataType: 'json',
            beforeSend: function () {
                loading.init($('.mod-create'));
                cyb.add.d.isReady = false;
                cyb.add.btn.closeTips();
            },
            success: function (r) {
                cyb.add.d.isReady = true;
                $('.loadDiv').remove();
                if (r.code == 1) {
                    comNotice.init('处理成功!');
                    setTimeout(function () {
                        cyb.add.d.isPull = true;
                        $('.mh-left a').click();
                    }, 500);
                } else {
                    comNotice.init(r.result || r.msg);
                    //IyData.reOAuth(r.code);
                }
            },
            error: function () {
                cyb.add.d.isReady = true;
            }
        })
    },
    getDomainTree: function (c) {//获取地域
        $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/region',
            dataType: 'json',
            success: function (r) {
                if(r.code==1){
                    var nd = {};
                    nd.lists = r.result;
                    c(nd)
                }else{
                    comNotice.init(r.msg);
                }
            }
        });
    },
    getIndustryTree: function (c) {//获取行业
        $.ajax({
            type: 'get',
            url: '/Cyberspace/sys/industry',
            dataType: 'json',
            success: function (r) {
                if(r.code==1){
                    var nd = {};
                    nd.lists = r.result;
                    c(nd)
                }else{
                    comNotice.init(r.msg);
                }
            }
        });
    },
    //认证
    OAuth: function () {
        $.ajax({
            type: 'post',
            url: '/Cyberspace/tourist/redirectOAuth.do',
            dataType: 'json',
            success: function (r) {
                if (r.code == 0) {
                    window.location.href = r.result;
                } else {
                    comNotice.init(r.msg)
                }
            },
            error: function () {
                comNotice.init('Error From OAuth！');
            }
        });
    }
};

var riskLevelToString=function(v){
    var d=['','很高','高','中等','低','很低'];
    return d[v]
};
var eventLevelToString=function(v){
    var d=['','特别重大','重大','较大','一般','其他'];
    return d[v]
};
